<template>
  <el-row>
    <el-col :span="24">
      <el-tabs v-model="activeName">
        <el-tab-pane label="订单信息" name="1">
          <keep-alive>
            <order-info expatriate @refresh="refresh" v-if="activeName == 1" :detail="detail"></order-info>
          </keep-alive>
        </el-tab-pane>
        <el-tab-pane label="服务信息" name="2">
          <keep-alive>
            <service-info v-if="activeName == 2" :id="id" :orderId="orderId">
              <div slot="tools">
                <div><el-button type="primary" @click="payment">支付</el-button></div>
                <div><el-button type="text" @click="changeWorker">更换服务方</el-button></div>
                <div><el-button type="text" @click="cancelOffer">取消外派</el-button></div>
              </div>
            </service-info>
          </keep-alive>
        </el-tab-pane>
        <el-tab-pane label="报价信息" name="3">
          <keep-alive>
            <quote-info v-if="activeName == 3" :id="id" :orderId="orderId" :detail="detail" flag="pending"></quote-info>
          </keep-alive>
        </el-tab-pane>
        <el-tab-pane label="跟进记录" name="4">
          <keep-alive>
            <FollowUp v-if="activeName == 4" :id="id" :objectId="objectId" :objectType="objectType"></FollowUp>
          </keep-alive>
        </el-tab-pane>
      </el-tabs>
    </el-col>
    <modal-fees-detail ref="modalFeesDetail" :orderId="orderId"></modal-fees-detail>
  </el-row>
</template>
<script>
import OrderInfo from '@/views/oms/orders/serviceOrders/detail/OrderInfo'
import ServiceInfo from '@/views/oms/orders/expatriate/detail/ServiceInfo'
import QuoteInfo from '@/views/oms/orders/expatriate/detail/QuoteInfo'
import modalFeesDetail from '@/views/fhb/myOrders/components/modal/modalFeesDetail'
import {unixTimestampFilter, filterDataBaseDictionary, decimalNumFilter} from '@/filters'
import FollowUp from '@/views/oms/business/FollowUp'
import {confirm} from '@/utils'
export default {
  name: 'serviceOrdersShow',
  components: {
    FollowUp,
    OrderInfo,
    ServiceInfo,
    QuoteInfo,
    modalFeesDetail
  },
  filters: {
    decimalNumFilter,
    filterDataBaseDictionary,
    unixTimestampFilter
  },
  data() {
    return {
      activeName: this.$route.query.tab ? String(this.$route.query.tab) : '1',
      objectId: this.$route.query.objectId ? String(this.$route.query.objectId) : '',
      objectType: this.$route.query.objectType ? String(this.$route.query.objectType) : '',
      id: this.$route.params.id,
      orderId: this.$route.query.orderId,
      detail: {}
    }
  },
  created() {
    this.getDetail()
  },
  methods: {
    getDetail() {
      this.$ajax.get('/ms-terminal-order/orderData/getOrderDatails', {orderId: this.orderId}).then(response => {
        if (!response.data) {
          return
        }
        this.detail = response.data || {}
      })
    },
    refresh() {
      this.getDetail()
    },
    // 支付
    payment() {
      this.$router.push({path: '/ss-oms/orders/expatriate/pending/payment/' + this.id, query: {orderId: this.orderId}})
    },
    // 更换服务方
    changeWorker() {
      this.activeName = '3'
    },
    // 取消订单
    cancelOffer() {
      let postData = {
        id: this.id
      }
      confirm('你确定要取消该外派吗？<br/> 取消外派后该订单将原路返回至抛出竞价之前的状态，可在系统中继续操作该订单', '温馨提示', {
        confirmButtonLoading: true,
        dangerouslyUseHTMLString: true,
        type: 'warning',
        center: false,
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        confirmCallBack: ({confirmButtonLoadingClose, close}) => {
          return this.$ajax.post('/ms-terminal-order/bidding/order-cancel', postData).then(response => {
            if (response.success) {
              close().then(_ => {
                this.$message({
                  type: 'success',
                  message: '操作成功!'
                })
                this.$router.push({path: '/redirect/ss-oms/orders/expatriate/offering/index'})
              })
            } else {
              confirmButtonLoadingClose()
            }
          }).finally(_ => {
            confirmButtonLoadingClose()
          })
        }
      })
    }
  }
}
</script>
